home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / cagd1gen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  50.4 KB  |  1,078 lines

  1. /******************************************************************************
  2. * Cagd_gen.c - General routines used by all modules of CAGD_lib.          *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Mar. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include <string.h>
  8. #include "cagd_loc.h"
  9. #include "geomat3d.h"
  10. #include "miscattr.h"
  11.  
  12. /*****************************************************************************
  13. * DESCRIPTION:                                                               M
  14. *   Allocates the memory required for a new curve.                          M
  15. *                                                                            *
  16. * PARAMETERS:                                                                M
  17. *   GType:      Type of geometry the curve should be - Bspline, Bezier etc.  M
  18. *   PType:      Type of control points (E2, P3, etc.).                       M
  19. *   Length:     Number of control points                                     M
  20. *                                                                            *
  21. * RETURN VALUE:                                                              M
  22. *   CagdCrvStruct *:   An uninitialized freeform curve.                      M
  23. *                                                                            *
  24. * KEYWORDS:                                                                  M
  25. *   CagdCrvNew, allocation                                                   M
  26. *****************************************************************************/
  27. CagdCrvStruct *CagdCrvNew(CagdGeomType GType, CagdPointType PType, int Length)
  28. {
  29.     int i,
  30.     MaxAxis = CAGD_NUM_OF_PT_COORD(PType);
  31.     CagdCrvStruct
  32.     *NewCrv = (CagdCrvStruct *) IritMalloc(sizeof(CagdCrvStruct));
  33.  
  34.     NewCrv -> GType = GType;
  35.     NewCrv -> PType = PType;
  36.     NewCrv -> Length = Length;
  37.     NewCrv -> Order = 0;
  38.     NewCrv -> Periodic = FALSE;
  39.     NewCrv -> KnotVector = NULL;
  40.     NewCrv -> Pnext = NULL;
  41.     NewCrv -> Attr = NULL;
  42.     NewCrv -> Points[0] = NULL;                /* The rational element. */
  43.  
  44.     for (i = !CAGD_IS_RATIONAL_PT(PType); i <= MaxAxis; i++)
  45.     NewCrv -> Points[i] = (CagdRType *) IritMalloc(sizeof(CagdRType) *
  46.                                  Length);
  47.  
  48.     for (i = MaxAxis + 1; i <= CAGD_MAX_PT_COORD; i++)
  49.     NewCrv -> Points[i] = NULL;
  50.  
  51.     return NewCrv;
  52. }
  53.  
  54. /*****************************************************************************
  55. * DESCRIPTION:                                                               M
  56. *   Allocates the memory required for a new, possibly periodic, curve.       M
  57. *                                                                            *
  58. * PARAMETERS:                                                                M
  59. *   GType:      Type of geometry the curve should be - Bspline, Bezier etc.  M
  60. *   PType:      Type of control points (E2, P3, etc.).                       M
  61. *   Length:     Number of control points                                     M
  62. *   Periodic:   Is this curve periodic?                                      M
  63. *                                                                            *
  64. * RETURN VALUE:                                                              M
  65. *   CagdCrvStruct *:   An uninitialized freeform curve.                      M
  66. *                                                                            *
  67. * KEYWORDS:                                                                  M
  68. *   CagdPeriodicCrvNew, allocation                                           M
  69. *****************************************************************************/
  70. CagdCrvStruct *CagdPeriodicCrvNew(CagdGeomType GType,
  71.                   CagdPointType PType,
  72.                   int Length,
  73.                   CagdBType Periodic)
  74. {
  75.     int i,
  76.     MaxAxis = CAGD_NUM_OF_PT_COORD(PType);
  77.     CagdCrvStruct
  78.     *NewCrv = (CagdCrvStruct *) IritMalloc(sizeof(CagdCrvStruct));
  79.  
  80.     NewCrv -> GType = GType;
  81.     NewCrv -> PType = PType;
  82.     NewCrv -> Length = Length;
  83.     NewCrv -> Order = 0;
  84.     NewCrv -> Periodic = Periodic;
  85.     NewCrv -> KnotVector = NULL;
  86.     NewCrv -> Pnext = NULL;
  87.     NewCrv -> Attr = NULL;
  88.     NewCrv -> Points[0] = NULL;                /* The rational element. */
  89.  
  90.     for (i = !CAGD_IS_RATIONAL_PT(PType); i <= MaxAxis; i++)
  91.     NewCrv -> Points[i] = (CagdRType *) IritMalloc(sizeof(CagdRType) *
  92.                                  Length);
  93.  
  94.     for (i = MaxAxis + 1; i <= CAGD_MAX_PT_COORD; i++)
  95.     NewCrv -> Points[i] = NULL;
  96.  
  97.     return NewCrv;
  98. }
  99.  
  100. /*****************************************************************************
  101. * DESCRIPTION:                                                               M
  102. *   Allocates the memory required for a new surface.                          M
  103. *                                                                            *
  104. * PARAMETERS:                                                                M
  105. *   GType:      Type of geometry the surface should be - Bspline, Bezier etc.M
  106. *   PType:      Type of control points (E2, P3, etc.).                       M
  107. *   ULength:    Number of control points in the U direction.                 M
  108. *   VLength:    Number of control points in the V direction.                 M
  109. *                                                                            *
  110. * RETURN VALUE:                                                              M
  111. *   CagdSrfStruct *:   An uninitialized freeform surface.                    M
  112. *                                                                            *
  113. * KEYWORDS:                                                                  M
  114. *   CagdSrfNew, allocation                                                   M
  115. *****************************************************************************/
  116. CagdSrfStruct *CagdSrfNew(CagdGeomType GType,
  117.               CagdPointType PType,
  118.               int ULength,
  119.               int VLength)
  120. {
  121.     int i,
  122.     MaxAxis = CAGD_NUM_OF_PT_COORD(PType);
  123.     CagdSrfStruct
  124.     *NewSrf = (CagdSrfStruct *) IritMalloc(sizeof(CagdSrfStruct));
  125.  
  126.     NewSrf -> GType = GType;
  127.     NewSrf -> PType = PType;
  128.     NewSrf -> ULength = ULength;
  129.     NewSrf -> VLength = VLength;
  130.     NewSrf -> UOrder = 0;
  131.     NewSrf -> VOrder = 0;
  132.     NewSrf -> UKnotVector = NULL;
  133.     NewSrf -> VKnotVector = NULL;
  134.     NewSrf -> UPeriodic = FALSE;
  135.     NewSrf -> VPeriodic = FALSE;
  136.     NewSrf -> Pnext = NULL;
  137.     NewSrf -> Attr = NULL;
  138.     NewSrf -> Points[0] = NULL;                /* The rational element. */
  139.  
  140.     for (i = !CAGD_IS_RATIONAL_PT(PType); i <= MaxAxis; i++)
  141.     NewSrf -> Points[i] = (CagdRType *) IritMalloc(sizeof(CagdRType) *
  142.                             ULength * VLength);
  143.  
  144.     for (i = MaxAxis + 1; i <= CAGD_MAX_PT_COORD; i++)
  145.     NewSrf -> Points[i] = NULL;
  146.  
  147.     return NewSrf;
  148. }
  149.  
  150. /*****************************************************************************
  151. * DESCRIPTION:                                                               M
  152. *   Allocates the memory required for a new, possibly periodic, surface.     M
  153. *                                                                            *
  154. * PARAMETERS:                                                                M
  155. *   GType:      Type of geometry the surface should be - Bspline, Bezier etc.M
  156. *   PType:      Type of control points (E2, P3, etc.).                       M
  157. *   ULength:    Number of control points in the U direction.                 M
  158. *   VLength:    Number of control points in the V direction.                 M
  159. *   UPeriodic:  Is this surface periodic in the U direction?                 M
  160. *   VPeriodic:  Is this surface periodic in the V direction?                 M
  161. *                                                                            *
  162. * RETURN VALUE:                                                              M
  163. *   CagdSrfStruct *:   An uninitialized freeform surface.                    M
  164. *                                                                            *
  165. * KEYWORDS:                                                                  M
  166. *   CagdPeriodicSrfNew, allocation                                           M
  167. *****************************************************************************/
  168. CagdSrfStruct *CagdPeriodicSrfNew(CagdGeomType GType,
  169.                   CagdPointType PType,
  170.                   int ULength,
  171.                   int VLength,
  172.                   CagdBType UPeriodic,
  173.                   CagdBType VPeriodic)
  174. {
  175.     int i,
  176.     MaxAxis = CAGD_NUM_OF_PT_COORD(PType);
  177.     CagdSrfStruct
  178.     *NewSrf = (CagdSrfStruct *) IritMalloc(sizeof(CagdSrfStruct));
  179.  
  180.     NewSrf -> GType = GType;
  181.     NewSrf -> PType = PType;
  182.     NewSrf -> ULength = ULength;
  183.     NewSrf -> VLength = VLength;
  184.     NewSrf -> UOrder = 0;
  185.     NewSrf -> VOrder = 0;
  186.     NewSrf -> UKnotVector = NULL;
  187.     NewSrf -> VKnotVector = NULL;
  188.     NewSrf -> UPeriodic = UPeriodic;
  189.     NewSrf -> VPeriodic = VPeriodic;
  190.     NewSrf -> Pnext = NULL;
  191.     NewSrf -> Attr = NULL;
  192.     NewSrf -> Points[0] = NULL;                /* The rational element. */
  193.  
  194.     for (i = !CAGD_IS_RATIONAL_PT(PType); i <= MaxAxis; i++)
  195.     NewSrf -> Points[i] = (CagdRType *) IritMalloc(sizeof(CagdRType) *
  196.                             ULength * VLength);
  197.  
  198.     for (i = MaxAxis + 1; i <= CAGD_MAX_PT_COORD; i++)
  199.     NewSrf -> Points[i] = NULL;
  200.  
  201.     return NewSrf;
  202. }
  203.  
  204. /*****************************************************************************
  205. * DESCRIPTION:                                                               M
  206. * Allocates and resets all slots of an array of UV structures.             M
  207. *                                                                            *
  208. * PARAMETERS:                                                                M
  209. *   Size:      Size of UV array to allocate.                                 M
  210. *                                                                            *
  211. * RETURN VALUE:                                                              M
  212. *   CagdUVStruct *:  An array of UV structures of size Size.                 M
  213. *                                                                            *
  214. * KEYWORDS:                                                                  M
  215. *   CagdUVArrayNew, allocation                                               M
  216. *****************************************************************************/
  217. CagdUVStruct *CagdUVArrayNew(int Size)
  218. {
  219.     int i;
  220.     CagdUVStruct
  221.     *NewUV = (CagdUVStruct *) IritMalloc(Size * sizeof(CagdUVStruct));
  222.  
  223.     for (i = 0; i < Size; i++) {
  224.     NewUV[i].Pnext = NULL;
  225.     NewUV[i].Attr = NULL;
  226.     }
  227.  
  228.     return NewUV;
  229. }
  230.  
  231. /*****************************************************************************
  232. * DESCRIPTION:                                                               M
  233. * Allocates and resets all slots of a UV structure.                 M
  234. *                                                                            *
  235. * PARAMETERS:                                                                M
  236. *   None                                                                     M
  237. *                                                                            *
  238. * RETURN VALUE:                                                              M
  239. *   CagdUVStruct *:  A UV structure.                             M
  240. *                                                                            *
  241. * KEYWORDS:                                                                  M
  242. *   CagdUVNew, allocation                                                    M
  243. *****************************************************************************/
  244. CagdUVStruct *CagdUVNew(void)
  245. {
  246.     CagdUVStruct
  247.     *NewUV = (CagdUVStruct *) IritMalloc(sizeof(CagdUVStruct));
  248.  
  249.     NewUV -> Pnext = NULL;
  250.     NewUV -> Attr = NULL;
  251.  
  252.     return NewUV;
  253. }
  254.  
  255. /*****************************************************************************
  256. * DESCRIPTION:                                                               M
  257. * Allocates and resets all slots of an array of Pt structures.             M
  258. *                                                                            *
  259. * PARAMETERS:                                                                M
  260. *   Size:      Size of Pt array to allocate.                                 M
  261. *                                                                            *
  262. * RETURN VALUE:                                                              M
  263. *   CagdPtStruct *:  An array of Pt structures of size Size.                 M
  264. *                                                                            *
  265. * KEYWORDS:                                                                  M
  266. *   CagdPtArrayNew, allocation                                               M
  267. *****************************************************************************/
  268. CagdPtStruct *CagdPtArrayNew(int Size)
  269. {
  270.     int i;
  271.     CagdPtStruct
  272.     *NewPt = (CagdPtStruct *) IritMalloc(Size * sizeof(CagdPtStruct));
  273.  
  274.     for (i = 0; i < Size; i++) {
  275.     NewPt[i].Pnext = NULL;
  276.     NewPt[i].Attr = NULL;
  277.     }
  278.  
  279.     return NewPt;
  280. }
  281.  
  282. /*****************************************************************************
  283. * DESCRIPTION:                                                               M
  284. * Allocates and resets all slots of a Pt structure.                 M
  285. *                                                                            *
  286. * PARAMETERS:                                                                M
  287. *   None                                                                     M
  288. *                                                                            *
  289. * RETURN VALUE:                                                              M
  290. *   CagdPtStruct *:  A Pt structure.                             M
  291. *                                                                            *
  292. * KEYWORDS:                                                                  M
  293. *   CagdPtNew, allocation                                                    M
  294. *****************************************************************************/
  295. CagdPtStruct *CagdPtNew(void)
  296. {
  297.     CagdPtStruct
  298.     *NewPt = (CagdPtStruct *) IritMalloc(sizeof(CagdPtStruct));
  299.  
  300.     NewPt -> Pnext = NULL;
  301.     NewPt -> Attr = NULL;
  302.  
  303.     return NewPt;
  304. }
  305.  
  306. /*****************************************************************************
  307. * DESCRIPTION:                                                               M
  308. * Allocates and resets all slots of an array of CtlPt structures.         M
  309. *                                                                            *
  310. * PARAMETERS:                                                                M
  311. *   Size:      Size of CtlPt array to allocate.                              M
  312. *                                                                            *
  313. * RETURN VALUE:                                                              M
  314. *   CagdCtlPtStruct *:  An array of CtlPt structures of size Size.           M
  315. *                                                                            *
  316. * KEYWORDS:                                                                  M
  317. *   CagdCtlPtArrayNew, allocation                                            M
  318. *****************************************************************************/
  319. CagdCtlPtStruct *CagdCtlPtArrayNew(CagdPointType PtType, int Size)
  320. {
  321.     int i;
  322.     CagdCtlPtStruct
  323.     *NewCtlPt = (CagdCtlPtStruct *)
  324.         IritMalloc(Size * sizeof(CagdCtlPtStruct));
  325.  
  326.     for (i = 0; i < Size; i++) {
  327.     NewCtlPt[i].Pnext = NULL;
  328.     NewCtlPt[i].Attr = NULL;
  329.     NewCtlPt[i].PtType = PtType;
  330.     }
  331.  
  332.     return NewCtlPt;
  333. }
  334.  
  335. /*****************************************************************************
  336. * DESCRIPTION:                                                               M
  337. * Allocates and resets all slots of a CtlPt structure.                 M
  338. *                                                                            *
  339. * PARAMETERS:                                                                M
  340. *   None                                                                     M
  341. *                                                                            *
  342. * RETURN VALUE:                                                              M
  343. *   CagdUVStruct *:  A CtlPt structure.                             M
  344. *                                                                            *
  345. * KEYWORDS:                                                                  M
  346. *   CagdCtlPtNew, allocation                                                 M
  347. *****************************************************************************/
  348. CagdCtlPtStruct *CagdCtlPtNew(CagdPointType PtType)
  349. {
  350.     CagdCtlPtStruct
  351.     *NewCtlPt = (CagdCtlPtStruct *) IritMalloc(sizeof(CagdCtlPtStruct));
  352.  
  353.     NewCtlPt -> Pnext = NULL;
  354.     NewCtlPt -> Attr = NULL;
  355.     NewCtlPt -> PtType = PtType;
  356.  
  357.     return NewCtlPt;
  358. }
  359.  
  360. /*****************************************************************************
  361. * DESCRIPTION:                                                               M
  362. * Allocates and resets all slots of an array of Vec structures.             M
  363. *                                                                            *
  364. * PARAMETERS:                                                                M
  365. *   Size:      Size of Vec array to allocate.                                M
  366. *                                                                            *
  367. * RETURN VALUE:                                                              M
  368. *   CagdVecStruct *:  An array of Vec structures of size Size.               M
  369. *                                                                            *
  370. * KEYWORDS:                                                                  M
  371. *   CagdVecArrayNew, allocation                                              M
  372. *****************************************************************************/
  373. CagdVecStruct *CagdVecArrayNew(int Size)
  374. {
  375.     int i;
  376.     CagdVecStruct
  377.     *NewVec = (CagdVecStruct *) IritMalloc(Size * sizeof(CagdVecStruct));
  378.  
  379.     for (i = 0; i < Size; i++) {
  380.     NewVec[i].Pnext = NULL;
  381.     NewVec[i].Attr = NULL;
  382.     }
  383.  
  384.     return NewVec;
  385. }
  386.  
  387. /*****************************************************************************
  388. * DESCRIPTION:                                                               M
  389. * Allocates and resets all slots of a Vec structure.                 M
  390. *                                                                            *
  391. * PARAMETERS:                                                                M
  392. *   None                                                                     M
  393. *                                                                            *
  394. * RETURN VALUE:                                                              M
  395. *   CagdVecStruct *:  A Vec structure.                             M
  396. *                                                                            *
  397. * KEYWORDS:                                                                  M
  398. *   CagdVecNew, allocation                                                   M
  399. *****************************************************************************/
  400. CagdVecStruct *CagdVecNew(void)
  401. {
  402.     CagdVecStruct
  403.     *NewVec = (CagdVecStruct *) IritMalloc(sizeof(CagdVecStruct));
  404.  
  405.     NewVec -> Pnext = NULL;
  406.     NewVec -> Attr = NULL;
  407.  
  408.     return NewVec;
  409. }
  410.  
  411. /*****************************************************************************
  412. * DESCRIPTION:                                                               M
  413. * Allocates and resets all slots of an array of Plane structures.         M
  414. *                                                                            *
  415. * PARAMETERS:                                                                M
  416. *   Size:      Size of Plane array to allocate.                              M
  417. *                                                                            *
  418. * RETURN VALUE:                                                              M
  419. *   CagdPlaneStruct *:  An array of Plane structures of size Size.           M
  420. *                                                                            *
  421. * KEYWORDS:                                                                  M
  422. *   CagdPlaneArrayNew, allocation                                            M
  423. *****************************************************************************/
  424. CagdPlaneStruct *CagdPlaneArrayNew(int Size)
  425. {
  426.     int i;
  427.     CagdPlaneStruct
  428.     *NewPlane = (CagdPlaneStruct *)
  429.         IritMalloc(Size * sizeof(CagdPlaneStruct));
  430.  
  431.     for (i = 0; i < Size; i++) {
  432.     NewPlane[i].Pnext = NULL;
  433.     NewPlane[i].Attr = NULL;
  434.     }
  435.  
  436.     return NewPlane;
  437. }
  438.  
  439. /*****************************************************************************
  440. * DESCRIPTION:                                                               M
  441. * Allocates and resets all slots of a Plane structure.                 M
  442. *                                                                            *
  443. * PARAMETERS:                                                                M
  444. *   None                                                                     M
  445. *                                                                            *
  446. * RETURN VALUE:                                                              M
  447. *   CagdUVStruct *:  A Plane structure.                             M
  448. *                                                                            *
  449. * KEYWORDS:                                                                  M
  450. *   CagdPlaneNew, allocation                                                 M
  451. *****************************************************************************/
  452. CagdPlaneStruct *CagdPlaneNew(void)
  453. {
  454.     CagdPlaneStruct
  455.     *NewPlane = (CagdPlaneStruct *) IritMalloc(sizeof(CagdPlaneStruct));
  456.  
  457.     NewPlane -> Pnext = NULL;
  458.     NewPlane -> Attr = NULL;
  459.  
  460.     return NewPlane;
  461. }
  462.  
  463. /*****************************************************************************
  464. * DESCRIPTION:                                                               M
  465. * Allocates and resets all slots of an array of BBox structures.         M
  466. *                                                                            *
  467. * PARAMETERS:                                                                M
  468. *   Size:      Size of BBox array to allocate.                               M
  469. *                                                                            *
  470. * RETURN VALUE:                                                              M
  471. *   CagdBBoxStruct *:  An array of BBox structures of size Size.             M
  472. *                                                                            *
  473. * KEYWORDS:                                                                  M
  474. *   CagdBBoxArrayNew, allocation                                             M
  475. *****************************************************************************/
  476. CagdBBoxStruct *CagdBBoxArrayNew(int Size)
  477. {
  478.     int i;
  479.     CagdBBoxStruct
  480.     *NewBBox = (CagdBBoxStruct *)
  481.         IritMalloc(Size * sizeof(CagdBBoxStruct));
  482.  
  483.     for (i = 0; i < Size; i++) {
  484.     NewBBox[i].Pnext = NULL;
  485.     NewBBox[i].Attr = NULL;
  486.     }
  487.  
  488.     return NewBBox;
  489. }
  490.  
  491. /*****************************************************************************
  492. * DESCRIPTION:                                                               M
  493. * Allocates and resets all slots of a BBox structure.                 M
  494. *                                                                            *
  495. * PARAMETERS:                                                                M
  496. *   None                                                                     M
  497. *                                                                            *
  498. * RETURN VALUE:                                                              M
  499. *   CagdBBoxStruct *:  A BBox structure.                         M
  500. *                                                                            *
  501. * KEYWORDS:                                                                  M
  502. *   CagdBBoxNew, allocation                                                  M
  503. *****************************************************************************/
  504. CagdBBoxStruct *CagdBBoxNew(void)
  505. {
  506.     CagdBBoxStruct
  507.     *NewBBox = (CagdBBoxStruct *) IritMalloc(sizeof(CagdBBoxStruct));
  508.  
  509.     NewBBox -> Pnext = NULL;
  510.     NewBBox -> Attr = NULL;
  511.  
  512.     return NewBBox;
  513. }
  514.  
  515. /*****************************************************************************
  516. * DESCRIPTION:                                                               M
  517. * Allocates and resets all slots of an array of Polygon structures.          M
  518. *                                                                            *
  519. * PARAMETERS:                                                                M
  520. *   Size:      Size of Polygon array to allocate.                            M
  521. *                                                                            *
  522. * RETURN VALUE:                                                              M
  523. *   CagdPolygonStruct *:  An array of Polygon structures of size Size.       M
  524. *                                                                            *
  525. * KEYWORDS:                                                                  M
  526. *   CagdPolygonArrayNew, allocation                                          M
  527. *****************************************************************************/
  528. CagdPolygonStruct *CagdPolygonArrayNew(int Size)
  529. {
  530.     int i;
  531.     CagdPolygonStruct
  532.     *NewPoly = (CagdPolygonStruct *)
  533.         IritMalloc(Size * sizeof(CagdPolygonStruct));
  534.  
  535.     for (i = 0; i < Size; i++) {
  536.     NewPoly[i].Pnext = NULL;
  537.     NewPoly[i].Attr = NULL;
  538.     }
  539.  
  540.     return NewPoly;
  541. }
  542.  
  543. /*****************************************************************************
  544. * DESCRIPTION:                                                               M
  545. * Allocates and resets all slots of a Polygon structure.             M
  546. *                                                                            *
  547. * PARAMETERS:                                                                M
  548. *   None                                                                     M
  549. *                                                                            *
  550. * RETURN VALUE:                                                              M
  551. *   CagdPolygonStruct *:  A Polygon structure.                             M
  552. *                                                                            *
  553. * KEYWORDS:                                                                  M
  554. *   CagdPolygonNew, allocation                                               M
  555. *****************************************************************************/
  556. CagdPolygonStruct *CagdPolygonNew(void)
  557. {
  558.     CagdPolygonStruct
  559.     *NewPoly = (CagdPolygonStruct *) IritMalloc(sizeof(CagdPolygonStruct));
  560.  
  561.     NewPoly -> Pnext = NULL;
  562.     NewPoly -> Attr = NULL;
  563.  
  564.     return NewPoly;
  565. }
  566.  
  567. /*****************************************************************************
  568. * DESCRIPTION:                                                               M
  569. * Allocates and resets all slots of an array of Polyline structures.         M
  570. *                                                                            *
  571. * PARAMETERS:                                                                M
  572. *   Size:      Size of Polyline array to allocate.                           M
  573. *                                                                            *
  574. * RETURN VALUE:                                                              M
  575. *   CagdPolylineStruct *:  An array of Polyline structures of size Size.     M
  576. *                                                                            *
  577. * KEYWORDS:                                                                  M
  578. *   CagdPolylineArrayNew, allocation                                         M
  579. *****************************************************************************/
  580. CagdPolylineStruct *CagdPolylineArrayNew(int Length, int Size)
  581. {
  582.     int i;
  583.     CagdPolylineStruct
  584.     *NewPoly = (CagdPolylineStruct *)
  585.         IritMalloc(Size * sizeof(CagdPolylineStruct));
  586.  
  587.     for (i = 0; i < Size; i++) {
  588.     NewPoly[i].Pnext = NULL;
  589.     NewPoly[i].Attr = NULL;
  590.     NewPoly[i].Polyline = (CagdPolylnStruct *)
  591.         IritMalloc(sizeof(CagdPolylnStruct) * Length);
  592.     NewPoly[i].Length = Length;
  593.     }
  594.  
  595.     return NewPoly;
  596. }
  597. /*****************************************************************************
  598. * DESCRIPTION:                                                               M
  599. * Allocates and resets all slots of a Polyline structure.             M
  600. *                                                                            *
  601. * PARAMETERS:                                                                M
  602. *   None                                                                     M
  603. *                                                                            *
  604. * RETURN VALUE:                                                              M
  605. *   CagdPolylineStruct *:  A Polyline structure.                     M
  606. *                                                                            *
  607. * KEYWORDS:                                                                  M
  608. *   CagdPolylineNew, allocation                                              M
  609. *****************************************************************************/
  610. CagdPolylineStruct *CagdPolylineNew(int Length)
  611. {
  612.     CagdPolylineStruct
  613.     *NewPoly = (CagdPolylineStruct *)
  614.         IritMalloc(sizeof(CagdPolylineStruct));
  615.  
  616.     NewPoly -> Pnext = NULL;
  617.     NewPoly -> Attr = NULL;
  618.     NewPoly -> Polyline = (CagdPolylnStruct *)
  619.     IritMalloc(sizeof(CagdPolylnStruct) * Length);
  620.     NewPoly -> Length = Length;
  621.  
  622.     return NewPoly;
  623. }
  624.  
  625. /*****************************************************************************
  626. * DESCRIPTION:                                                               M
  627. * Allocates and copies all slots of a curve structure.                 M
  628. *                                                                            *
  629. * PARAMETERS:                                                                M
  630. *   Crv:       To be copied.                                                 M
  631. *                                                                            *
  632. * RETURN VALUE:                                                              M
  633. *   CagdCrvStruct *:  A duplicate of Crv.                                    M
  634. *                                                                            *
  635. * KEYWORDS:                                                                  M
  636. *   CagdCrvCopy, copy                                                        M
  637. *****************************************************************************/
  638. CagdCrvStruct *CagdCrvCopy(CagdCrvStruct *Crv)
  639. {
  640.     int i,
  641.     MaxAxis = CAGD_NUM_OF_PT_COORD(Crv -> PType);
  642.     CagdCrvStruct
  643.     *NewCrv = (CagdCrvStruct *) IritMalloc(sizeof(CagdCrvStruct));
  644.  
  645.     NewCrv -> GType = Crv -> GType;
  646.     NewCrv -> PType = Crv -> PType;
  647.     NewCrv -> Length = Crv -> Length;
  648.     NewCrv -> Order = Crv -> Order;
  649.     NewCrv -> Periodic = Crv -> Periodic;
  650.     if (Crv -> KnotVector != NULL)
  651.     NewCrv -> KnotVector = BspKnotCopy(Crv -> KnotVector,
  652.                    Crv -> Length + Crv -> Order +
  653.                    (Crv -> Periodic ? Crv -> Order - 1 : 0));
  654.     else
  655.     NewCrv -> KnotVector = NULL;
  656.     NewCrv -> Pnext = NULL;
  657.     NewCrv -> Attr = NULL;
  658.     NewCrv -> Points[0] = NULL;                /* The rational element. */
  659.  
  660.     for (i = !CAGD_IS_RATIONAL_PT(Crv -> PType); i <= MaxAxis; i++) {
  661.     NewCrv -> Points[i] = (CagdRType *) IritMalloc(sizeof(CagdRType) *
  662.                                    Crv -> Length);
  663.     CAGD_GEN_COPY(NewCrv -> Points[i], Crv -> Points[i],
  664.               sizeof(CagdRType) * Crv -> Length);
  665.     }
  666.  
  667.     for (i = MaxAxis + 1; i <= CAGD_MAX_PT_COORD; i++)
  668.     NewCrv -> Points[i] = NULL;
  669.  
  670.     return NewCrv;
  671. }
  672.  
  673. /*****************************************************************************
  674. * DESCRIPTION:                                                               M
  675. * Allocates and copies all slots of a surface structure.             M
  676. *                                                                            *
  677. * PARAMETERS:                                                                M
  678. *   Srf:       To be copied.                                                 M
  679. *                                                                            *
  680. * RETURN VALUE:                                                              M
  681. *   CagdSrfStruct *:  A duplicate of Srf.                                    M
  682. *                                                                            *
  683. * KEYWORDS:                                                                  M
  684. *   CagdSrfCopy, copy                                                        M
  685. *****************************************************************************/
  686. CagdSrfStruct *CagdSrfCopy(CagdSrfStruct *Srf)
  687. {
  688.     int i,
  689.     MaxAxis = CAGD_NUM_OF_PT_COORD(Srf -> PType);
  690.     CagdSrfStruct
  691.     *NewSrf = (CagdSrfStruct *) IritMalloc(sizeof(CagdSrfStruct));
  692.  
  693.     NewSrf -> GType = Srf -> GType;
  694.     NewSrf -> PType = Srf -> PType;
  695.     NewSrf -> ULength = Srf -> ULength;
  696.     NewSrf -> VLength = Srf -> VLength;
  697.     NewSrf -> UOrder = Srf -> UOrder;
  698.     NewSrf -> VOrder = Srf -> VOrder;
  699.     NewSrf -> UPeriodic = Srf -> UPeriodic;
  700.     NewSrf -> VPeriodic = Srf -> VPeriodic;
  701.     if (Srf -> UKnotVector != NULL)
  702.     NewSrf -> UKnotVector = BspKnotCopy(Srf -> UKnotVector,
  703.                    Srf -> ULength + Srf -> UOrder +
  704.                    (Srf -> UPeriodic ? Srf -> UOrder - 1 : 0));
  705.     else
  706.     NewSrf -> UKnotVector = NULL;
  707.     if (Srf -> VKnotVector != NULL)
  708.     NewSrf -> VKnotVector = BspKnotCopy(Srf -> VKnotVector,
  709.                    Srf -> VLength + Srf -> VOrder +
  710.                    (Srf -> VPeriodic ? Srf -> VOrder - 1 : 0));
  711.     else
  712.     NewSrf -> VKnotVector = NULL;
  713.     NewSrf -> Pnext = NULL;
  714.     NewSrf -> Attr = NULL;
  715.     NewSrf -> Points[0] = NULL;                /* The rational element. */
  716.  
  717.     for (i = !CAGD_IS_RATIONAL_PT(Srf -> PType); i <= MaxAxis; i++) {
  718.     NewSrf -> Points[i] = (CagdRType *) IritMalloc(sizeof(CagdRType) *
  719.                      Srf -> ULength * Srf -> VLength);
  720.     CAGD_GEN_COPY(NewSrf -> Points[i], Srf -> Points[i],
  721.               sizeof(CagdRType) * Srf -> ULength * Srf -> VLength);
  722.     }
  723.  
  724.     for (i = MaxAxis + 1; i <= CAGD_MAX_PT_COORD; i++)
  725.     NewSrf -> Points[i] = NULL;
  726.  
  727.     return NewSrf;
  728. }
  729.  
  730. /*****************************************************************************
  731. * DESCRIPTION:                                                               M
  732. * Allocates and copies all slots of a UV structure.                 M
  733. *                                                                            *
  734. * PARAMETERS:                                                                M
  735. *   UV:       To be copied.                                                  M
  736. *                                                                            *
  737. * RETURN VALUE:                                                              M
  738. *   CagdUVStruct *:  A duplicate of UV.                                      M
  739. *                                                                            *
  740. * KEYWORDS:                                                                  M
  741. *   CagdUVCopy, copy                                                         M
  742. *****************************************************************************/
  743. CagdUVStruct *CagdUVCopy(CagdUVStruct *UV)
  744. {
  745.     CagdUVStruct
  746.     *NewUV = (CagdUVStruct *) IritMalloc(sizeof(CagdUVStruct));
  747.  
  748.     CAGD_GEN_COPY(NewUV, UV, sizeof(CagdUVStruct));
  749.     NewUV -> Pnext = NULL;
  750.     NewUV -> Attr = AttrCopyAttributes(UV -> Attr);
  751.  
  752.     return NewUV;
  753. }
  754.  
  755. /*****************************************************************************
  756. * DESCRIPTION:                                                               M
  757. * Allocates and copies all slots of a Pt structure.                 M
  758. *                                                                            *
  759. * PARAMETERS:                                                                M
  760. *   Pt:       To be copied.                                                  M
  761. *                                                                            *
  762. * RETURN VALUE:                                                              M
  763. *   CagdPtStruct *:  A duplicate of Pt.                                      M
  764. *                                                                            *
  765. * KEYWORDS:                                                                  M
  766. *   CagdPtCopy, copy                                                         M
  767. *****************************************************************************/
  768. CagdPtStruct *CagdPtCopy(CagdPtStruct *Pt)
  769. {
  770.     CagdPtStruct
  771.     *NewPt = (CagdPtStruct *) IritMalloc(sizeof(CagdPtStruct));
  772.  
  773.     CAGD_GEN_COPY(NewPt, Pt, sizeof(CagdPtStruct));
  774.     NewPt -> Pnext = NULL;
  775.     NewPt -> Attr = AttrCopyAttributes(Pt -> Attr);
  776.  
  777.     return NewPt;
  778. }
  779.  
  780. /*****************************************************************************
  781. * DESCRIPTION:                                                               M
  782. * Allocates and copies all slots of a CtlPt structure.                 M
  783. *                                                                            *
  784. * PARAMETERS:                                                                M
  785. *   CtlPt:       To be copied.                                               M
  786. *                                                                            *
  787. * RETURN VALUE:                                                              M
  788. *   CagdUVStruct *:  A duplicate of CtlPt.                                   M
  789. *                                                                            *
  790. * KEYWORDS:                                                                  M
  791. *   CagdCtlPtCopy, copy                                                      M
  792. *****************************************************************************/
  793. CagdCtlPtStruct *CagdCtlPtCopy(CagdCtlPtStruct *CtlPt)
  794. {
  795.     CagdCtlPtStruct
  796.     *NewCtlPt = (CagdCtlPtStruct *) IritMalloc(sizeof(CagdCtlPtStruct));
  797.  
  798.     CAGD_GEN_COPY(NewCtlPt, CtlPt, sizeof(CagdCtlPtStruct));
  799.     NewCtlPt -> Pnext = NULL;
  800.     NewCtlPt -> Attr = AttrCopyAttributes(CtlPt -> Attr);
  801.  
  802.     return NewCtlPt;
  803. }
  804.  
  805. /*****************************************************************************
  806. * DESCRIPTION:                                                               M
  807. * Allocates and copies all slots of a Vec structure.                 M
  808. *                                                                            *
  809. * PARAMETERS:                                                                M
  810. *   Vec:       To be copied.                                                 M
  811. *                                                                            *
  812. * RETURN VALUE:                                                              M
  813. *   CagdUVStruct *:  A duplicate of Vec.                                     M
  814. *                                                                            *
  815. * KEYWORDS:                                                                  M
  816. *   CagdVecCopy, copy                                                        M
  817. *****************************************************************************/
  818. CagdVecStruct *CagdVecCopy(CagdVecStruct *Vec)
  819. {
  820.     CagdVecStruct
  821.     *NewVec = (CagdVecStruct *) IritMalloc(sizeof(CagdVecStruct));
  822.  
  823.     CAGD_GEN_COPY(NewVec, Vec, sizeof(CagdVecStruct));
  824.     NewVec -> Pnext = NULL;
  825.     NewVec -> Attr = AttrCopyAttributes(Vec -> Attr);
  826.  
  827.     return NewVec;
  828. }
  829.  
  830. /*****************************************************************************
  831. * DESCRIPTION:                                                               M
  832. * Allocates and copies all slots of a Plane structure.                 M
  833. *                                                                            *
  834. * PARAMETERS:                                                                M
  835. *   Plane:       To be copied.                                               M
  836. *                                                                            *
  837. * RETURN VALUE:                                                              M
  838. *   CagdPlaneStruct *:  A duplicate of Plane.                                M
  839. *                                                                            *
  840. * KEYWORDS:                                                                  M
  841. *   CagdPlaneCopy, copy                                                      M
  842. *****************************************************************************/
  843. CagdPlaneStruct *CagdPlaneCopy(CagdPlaneStruct *Plane)
  844. {
  845.     CagdPlaneStruct
  846.     *NewPlane = (CagdPlaneStruct *) IritMalloc(sizeof(CagdPlaneStruct));
  847.  
  848.     CAGD_GEN_COPY(NewPlane, Plane, sizeof(CagdPlaneStruct));
  849.     NewPlane -> Pnext = NULL;
  850.     NewPlane -> Attr = AttrCopyAttributes(Plane -> Attr);
  851.  
  852.     return NewPlane;
  853. }
  854.  
  855. /*****************************************************************************
  856. * DESCRIPTION:                                                               M
  857. * Allocates and copies all slots of a BBox structure.                 M
  858. *                                                                            *
  859. * PARAMETERS:                                                                M
  860. *   BBox:       To be copied.                                                M
  861. *                                                                            *
  862. * RETURN VALUE:                                                              M
  863. *   CagdBBoxStruct *:  A duplicate of BBox.                                  M
  864. *                                                                            *
  865. * KEYWORDS:                                                                  M
  866. *   CagdBBoxCopy, copy                                                       M
  867. *****************************************************************************/
  868. CagdBBoxStruct *CagdBBoxCopy(CagdBBoxStruct *BBox)
  869. {
  870.     CagdBBoxStruct
  871.     *NewBBox = (CagdBBoxStruct *) IritMalloc(sizeof(CagdBBoxStruct));
  872.  
  873.     CAGD_GEN_COPY(NewBBox, BBox, sizeof(CagdBBoxStruct));
  874.     NewBBox -> Pnext = NULL;
  875.     NewBBox -> Attr = AttrCopyAttributes(BBox -> Attr);
  876.  
  877.     return NewBBox;
  878. }
  879.  
  880. /*****************************************************************************
  881. * DESCRIPTION:                                                               M
  882. * Allocates and copies all slots of a Polygon structure.             M
  883. *                                                                            *
  884. * PARAMETERS:                                                                M
  885. *   Poly:       To be copied.                                                M
  886. *                                                                            *
  887. * RETURN VALUE:                                                              M
  888. *   CagdPolygonStruct *:  A duplicate of Polygon.                            M
  889. *                                                                            *
  890. * KEYWORDS:                                                                  M
  891. *   CagdPolygonCopy, copy                                                    M
  892. *****************************************************************************/
  893. CagdPolygonStruct *CagdPolygonCopy(CagdPolygonStruct *Poly)
  894. {
  895.     CagdPolygonStruct
  896.     *NewPoly = (CagdPolygonStruct *) IritMalloc(sizeof(CagdPolygonStruct));
  897.  
  898.     CAGD_GEN_COPY(NewPoly, Poly, sizeof(CagdPolygonStruct));
  899.     NewPoly -> Pnext = NULL;
  900.     NewPoly -> Attr = NULL;
  901.  
  902.     return NewPoly;
  903. }
  904.  
  905. /*****************************************************************************
  906. * DESCRIPTION:                                                               M
  907. * Allocates and copies all slots of a Polyline structure.                 M
  908. *                                                                            *
  909. * PARAMETERS:                                                                M
  910. *   Poly:       To be copied.                                                M
  911. *                                                                            *
  912. * RETURN VALUE:                                                              M
  913. *   CagdPolylineStruct *:  A duplicate of Polyline.                          M
  914. *                                                                            *
  915. * KEYWORDS:                                                                  M
  916. *   CagdPolylineCopy, copy                                                   M
  917. *****************************************************************************/
  918. CagdPolylineStruct *CagdPolylineCopy(CagdPolylineStruct *Poly)
  919. {
  920.     CagdPolylineStruct
  921.     *NewPoly = (CagdPolylineStruct *) IritMalloc(sizeof(CagdPolylineStruct));
  922.  
  923.     NewPoly -> Polyline = (CagdPolylnStruct *)
  924.     IritMalloc(sizeof(CagdPolylnStruct) * Poly -> Length);
  925.     CAGD_GEN_COPY(NewPoly -> Polyline, Poly -> Polyline,
  926.           sizeof(CagdPolylnStruct) * Poly -> Length);
  927.     NewPoly -> Pnext = NULL;
  928.     NewPoly -> Attr = NULL;
  929.     NewPoly -> Length = Poly -> Length;
  930.  
  931.     return NewPoly;
  932. }
  933.  
  934. /*****************************************************************************
  935. * DESCRIPTION:                                                               M
  936. * Allocates and copies a list of curve structures.                     M
  937. *                                                                            *
  938. * PARAMETERS:                                                                M
  939. *   CrvList:       To be copied.                                             M
  940. *                                                                            *
  941. * RETURN VALUE:                                                              M
  942. *   CagdCrvStruct *:  A duplicated list of curves.                           M
  943. *                                                                            *
  944. * KEYWORDS:                                                                  M
  945. *   CagdCrvCopyList, copy                                                    M
  946. *****************************************************************************/
  947. CagdCrvStruct *CagdCrvCopyList(CagdCrvStruct *CrvList)
  948. {
  949.     CagdCrvStruct *CrvTemp, *NewCrvList;
  950.  
  951.     if (CrvList == NULL)
  952.     return NULL;
  953.     CrvTemp = NewCrvList = CagdCrvCopy(CrvList);
  954.     CrvList = CrvList -> Pnext;
  955.     while (CrvList) {
  956.     CrvTemp -> Pnext = CagdCrvCopy(CrvList);
  957.     CrvTemp = CrvTemp -> Pnext;
  958.     CrvList = CrvList -> Pnext;
  959.     }
  960.     return NewCrvList;
  961. }
  962.  
  963. /*****************************************************************************
  964. * DESCRIPTION:                                                               M
  965. * Allocates and copies a list of surface structures.                     M
  966. *                                                                            *
  967. * PARAMETERS:                                                                M
  968. *   SrfList:       To be copied.                                             M
  969. *                                                                            *
  970. * RETURN VALUE:                                                              M
  971. *   CagdSrfStruct *:  A duplicated list of surfaces.                         M
  972. *                                                                            *
  973. * KEYWORDS:                                                                  M
  974. *   CagdSrfCopyList, copy                                                    M
  975. *****************************************************************************/
  976. CagdSrfStruct *CagdSrfCopyList(CagdSrfStruct *SrfList)
  977. {
  978.     CagdSrfStruct *SrfTemp, *NewSrfList;
  979.  
  980.     if (SrfList == NULL)
  981.     return NULL;
  982.     SrfTemp = NewSrfList = CagdSrfCopy(SrfList);
  983.     SrfList = SrfList -> Pnext;
  984.     while (SrfList) {
  985.     SrfTemp -> Pnext = CagdSrfCopy(SrfList);
  986.     SrfTemp = SrfTemp -> Pnext;
  987.     SrfList = SrfList -> Pnext;
  988.     }
  989.     return NewSrfList;
  990. }
  991.  
  992. /*****************************************************************************
  993. * DESCRIPTION:                                                               M
  994. * Allocates and copies a list of UV structures.                         M
  995. *                                                                            *
  996. * PARAMETERS:                                                                M
  997. *   UVList:       To be copied.                                              M
  998. *                                                                            *
  999. * RETURN VALUE:                                                              M
  1000. *   CagdUVStruct *:  A duplicated list of UV's.                              M
  1001. *                                                                            *
  1002. * KEYWORDS:                                                                  M
  1003. *   CagdUVCopyList, copy                                                     M
  1004. *****************************************************************************/
  1005. CagdUVStruct *CagdUVCopyList(CagdUVStruct *UVList)
  1006. {
  1007.     CagdUVStruct *UVTemp, *NewUVList;
  1008.  
  1009.     if (UVList == NULL)
  1010.     return NULL;
  1011.     UVTemp = NewUVList = CagdUVCopy(UVList);
  1012.     UVList = UVList -> Pnext;
  1013.     while (UVList) {
  1014.     UVTemp -> Pnext = CagdUVCopy(UVList);
  1015.     UVTemp = UVTemp -> Pnext;
  1016.     UVList = UVList -> Pnext;
  1017.     }
  1018.     return NewUVList;
  1019. }
  1020.  
  1021. /*****************************************************************************
  1022. * DESCRIPTION:                                                               M
  1023. * Allocates and copies a list of point structures.                     M
  1024. *                                                                            *
  1025. * PARAMETERS:                                                                M
  1026. *   PtList:       To be copied.                                              M
  1027. *                                                                            *
  1028. * RETURN VALUE:                                                              M
  1029. *   CagdPtStruct *:  A duplicated list of points.                            M
  1030. *                                                                            *
  1031. * KEYWORDS:                                                                  M
  1032. *   CagdPtCopyList, copy                                                     M
  1033. *****************************************************************************/
  1034. CagdPtStruct *CagdPtCopyList(CagdPtStruct *PtList)
  1035. {
  1036.     CagdPtStruct *PtTemp, *NewPtList;
  1037.  
  1038.     if (PtList == NULL)
  1039.     return NULL;
  1040.     PtTemp = NewPtList = CagdPtCopy(PtList);
  1041.     PtList = PtList -> Pnext;
  1042.     while (PtList) {
  1043.     PtTemp -> Pnext = CagdPtCopy(PtList);
  1044.     PtTemp = PtTemp -> Pnext;
  1045.     PtList = PtList -> Pnext;
  1046.     }
  1047.     return NewPtList;
  1048. }
  1049.  
  1050. /*****************************************************************************
  1051. * DESCRIPTION:                                                               M
  1052. * Allocates and copies a list of CtlPt structures.                     M
  1053. *                                                                            *
  1054. * PARAMETERS:                                                                M
  1055. *   CtlPtList:       To be copied.                                           M
  1056. *                                                                            *
  1057. * RETURN VALUE:                                                              M
  1058. *   CagdCtlPtStruct *:  A duplicated list of CtlPt's.                        M
  1059. *                                                                            *
  1060. * KEYWORDS:                                                                  M
  1061. *   CagdCtlPtCopyList, copy                                                  M
  1062. *****************************************************************************/
  1063. CagdCtlPtStruct *CagdCtlPtCopyList(CagdCtlPtStruct *CtlPtList)
  1064. {
  1065.     CagdCtlPtStruct *CtlPtTemp, *NewCtlPtList;
  1066.  
  1067.     if (CtlPtList == NULL)
  1068.     return NULL;
  1069.     CtlPtTemp = NewCtlPtList = CagdCtlPtCopy(CtlPtList);
  1070.     CtlPtList = CtlPtList -> Pnext;
  1071.     while (CtlPtList) {
  1072.     CtlPtTemp -> Pnext = CagdCtlPtCopy(CtlPtList);
  1073.     CtlPtTemp = CtlPtTemp -> Pnext;
  1074.     CtlPtList = CtlPtList -> Pnext;
  1075.     }
  1076.     return NewCtlPtList;
  1077. }
  1078.